<link rel="stylesheet" type="text/css" href="/public/webuploader/webuploader.css">
<link rel="stylesheet" type="text/css" href="public/webuploader/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="public/webuploader/bootstrap-theme.min.css">
<style>
  .layui-upload-img {
    width: 92px;
    height: 92px;
    margin: 0 10px 10px 0;
    border: 1px solid #c0c0c0;
  }
  .layui-form-label {
    width: 95px;
  }
  .webuploader-pick{
    background:none;
  }
  #picker .webuploader-pick{
    background: #00b7ee;
  }
</style>
<script src="/public/webuploader/webuploader.min.js"></script>
<link rel="stylesheet" type="text/css" href="/public/admin/layui_extends/formSelects-v4.css"/>
  <div class="layui-form" lay-filter="layuiadmin-video_small-form-list" id="layuiadmin-video_small-form-list"style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">视频标题</label>
      <div class="layui-input-inline">
        <script type="text/html" template>
          <textarea name="title" lay-verify="required" style="width: 400px; height: 100px;" autocomplete="off" class="layui-textarea title" >{{ d.params.title || '' }}</textarea>
          <input type="hidden" name="fm_img" value="{{ d.params.fm_img || '' }}" class="layui-input path">
          <input type="hidden" name="rec_fm_img" value="{{ d.params.rec_fm_img || '' }}" class="layui-input rec_path">
          <!--<input type="hidden" name="url" value="{{ d.params.url || '' }}" class="layui-input url">-->
          <input type="hidden" name="video_time" value="{{ d.params.video_time || '' }}" class="layui-input video_time">
          <!--<input type="hidden"  value="{{ d.params.video_id || '' }}" class="video_id">-->
        </script>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">视频简介</label>
      <div class="layui-input-inline">
        <script type="text/html" template>
          <textarea name="memo" lay-verify="required" style="width: 400px; height: 100px;" autocomplete="off" class="layui-textarea title">{{ d.params.memo || '' }}</textarea>
        </script>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">栏目</label>
      <div class="layui-input-inline">
        <script type="text/html" template lay-url="/admin/video/get_small_column_list"  lay-done="layui.data.done(d);" >
          <select name="column_id" lay-filter="column_id" lay-search="">
            <option value="">全部栏目</option>
            {{# layui.each(d.data,function(index,item){ }}
            <option value="{{item.id}}" {{# if(item.id == d.params.column_id){ }} selected {{# } }}>{{ item.name }}</option>
            {{# }); }}
          </select>
        </script>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">分类</label>
      <div class="layui-input-inline" style="width: 40%">
        <script type="text/html" template >
          <select name="cate_id_str"  xm-select="cate_id_str" xm-select-search=""  xm-select-search-type="dl">
          </select>
        </script>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">上映时间</label>
      <div class="layui-input-inline">
        <script type="text/html" template >
          <select name="video_time_id" xm-select="video_time_id"  xm-select-radio="" xm-select-search="/admin/video/get_video_time_list1?column_id={{d.params.column_id}}&video_time_id={{d.params.video_time_id}}"></select>
        </script>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">地区</label>
      <div class="layui-input-inline">
        <script type="text/html" template >
          <select name="address_id" xm-select="address_id" xm-select-radio="" xm-select-search="/admin/video/get_address_list1?column_id={{d.params.column_id}}&address_id={{d.params.address_id}}"></select>
        </script>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">标签</label>
      <div class="layui-input-inline" style="width: 80%">
        <script type="text/html" template lay-url="/admin/video/get_tag_list"  lay-done="layui.data.done(d);" >
          {{# layui.each(d.data,function(index,item){ }}
          <input type="checkbox" name="tag[{{item.id}}]" lay-skin="primary" title="{{item.name}}"  num="{{item.id}}" class="a{{item.id}} tag{{item.id}}">
          {{# }); }}
        </script>
      </div>
    </div>

    <div class="layui-upload">
      <label class="layui-form-label">封面图片</label>
      <!-- <button type="button" class="layui-btn" id="test1">上传图片</button>-->
      <div class="layui-upload-list" >
        <script type="text/html" template>
          {{#  if(d.params.fm_img){ }}
          <div id="filePicker" style="width: 300px"><img  src="{{d.params.http}}{{d.params.fm_img || ''}}" class="layui-upload-img" ></div>
          <!--<img class="layui-upload-img" id="demo1" src="{{d.params.http}}{{d.params.fm_img || ''}}">-->
          {{#  } else { }}
          <div id="filePicker" style="width: 300px"><img  class="layui-upload-img" ></div>
         <!-- <img class="layui-upload-img" id="demo1">-->
          {{#  } }}

        </script>

        <p id="demoText"></p>
      </div>
    </div>
    <div class="layui-upload">
      <label class="layui-form-label">上传视频</label>
      <div class="layui-upload-list">
        <script type="text/html" template>
          <input type="text" name="url" value="{{ d.params.url || '' }}" onkeyup="get_url(this.value)" lay-verify="required" autocomplete="off" class="layui-input url" style="width: 400px;float: left;margin-right: 5px" disabled>
          <div id="thelist" class="uploader-list"></div>
          <div class="btns" style="width: 100px;float: left">
            <div id="picker" style="">上传视频</div>
          </div>
          <div style="margin-top: 10px;margin-left: 40px">
            {{#  if(d.params.url){ }}
            <!--<video src="{{d.params.http}}{{d.params.url}}" width="400" height="230" controls="controls" class="video_url"></video>-->
            <div id="video" style="width: 900px; height: 600px;"></div>
            {{#  } else { }}
            <!--<video src="" width="400" height="230" controls="controls" class="video_url"></video>-->
            <div id="video" style="width: 900px; height: 600px;"></div>
            {{#  } }}
            <input type="hidden" value="{{d.params.http || 'http://jieshuodiapi.com'}}" class="http">

          </div>
        <!--  <input type="checkbox" name="m3u8" lay-skin="primary" title="是否转m3u8" class="m3u8">-->
        </script>

      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">视频时间</label>
      <div class="layui-input-inline">
        <script type="text/html" template>
          <input type="text" name="video_time" value="{{ d.params.video_time || '' }}" autocomplete="off" class="layui-input video_time">
        </script>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">语言</label>
      <div class="layui-input-inline">
        <script type="text/html" template>
          <input type="text" name="language" value="{{ d.params.language || '' }}" autocomplete="off" class="layui-input">
        </script>
      </div>
    </div>
    <script type="text/html" template>
      <input type="hidden" name="id" value="{{ d.params.id || '' }}">
      <input type="hidden" name="tag_str" value="{{ d.params.tag || '' }}" class="tag_str">
      <input type="hidden"  value="{{ d.params.uid || '' }}" class="uid">
      <input type="hidden"  value="{{ d.params.video_id || '' }}" class="video_id">
      <input type="hidden"  value="{{ d.params.column_id || '' }}" class="column_id">
      <input type="hidden"  value="{{ d.params.cate_id || '' }}" class="cate_id_str">
      <input type="hidden"  value="{{ d.params.m3u8_time || '' }}" class="edit_m3u8_time" name="m3u8_time">

    </script>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-inline">
        <input type="button" lay-submit lay-filter="layuiadmin-video_small-form-submit" value="确认" class="layui-btn">
      </div>
    </div>
  </div>
<script>
function get_url(val) {
  var arr = [ '.mp4', ".mov", ".avi", ".rmvb" ];
  for(var i=0;i<arr.length;i++){
    if(val.indexOf(arr[i]) != -1 ){
      if($('.m3u8').is(':checked') && val){
        layer.confirm('确定输入完毕,进行转码？', {
          btn: ['确定','否'] //按钮
        }, function(){
          layer.closeAll('dialog');
            var http=$('.http').val();
            $('.video_url').attr('src',http+val);
            var m3u8_time=$('.m3u8_time').val();
            var m3u8_width=$('.m3u8_width').val();
            var m3u8_height=$('.m3u8_height').val();
          var m3u8_status=2;
          if($('.m3u8').is(':checked')){
            m3u8_status=1;
          }
            $.ajax({
              type: "POST",
              url: "http://jieshuodiapi.com/video.php",
              data: {url:val,m3u8_time:m3u8_time,m3u8_width:m3u8_width,m3u8_height:m3u8_height,m3u8_status:m3u8_status},
              dataType: "json",
              beforeSend: function () {
                layer.load(1, {shade: [0.8, '#393D49']})//上传loading
              },
              success: function(data){
                if(data.code==0){
                  $('.url').val(data.src);
                  $('.video_time').val(data.video_time);
                  var http_url=$('.http').val();
                  $('.video_url').attr('src',http_url+data.src);
                  var videoObject = {
                    container: '#video',//“#”代表容器的ID，“.”或“”代表容器的class
                    variable: 'player',//该属性必需设置，值等于下面的new chplayer()的对象
                    autoplay:true,//自动播放
                    video:http_url+data.src//视频地址
                  };
                  var player=new ckplayer(videoObject);
                  layer.closeAll('loading'); //关闭loading
                }
              }
            });
        });
      }else if(val){
        $.ajax({
          type: "POST",
          url: "http://jieshuodiapi.com/video.php",
          data: {url:val},
          dataType: "json",
          beforeSend: function () {
            //layer.load(1, {shade: [0.8, '#393D49']})//上传loading
          },
          success: function(data){
            if(data.code==0){
              $('.url').val(data.src);
              $('.video_time').val(data.video_time);
              var http_url=$('.http').val();
              $('.video_url').attr('src',http_url+data.src);
              var videoObject = {
                container: '#video',//“#”代表容器的ID，“.”或“”代表容器的class
                variable: 'player',//该属性必需设置，值等于下面的new chplayer()的对象
                autoplay:true,//自动播放
                video:http_url+data.src//视频地址
              };
              var player=new ckplayer(videoObject);
              //layer.closeAll('loading'); //关闭loading
            }
          }
        });
      }

    }
  }



}
  layui.use(['form'], function(){
    var form = layui.form;
    setTimeout(function () {
      var video_id=$('.video_id').val();
      var column_id=$('.column_id').val();
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('video_id', 'server', {
          url: '/admin/video/get_video_list?video_id='+video_id,
          linkage: false,
          linkageWidth: 130,
          header: {token: '4b36adc7ff355357'},
          success: function(id, url, searchVal, result){
            layui.formSelects.value('video_id',video_id );
          }
        });
        layui.formSelects.on('video_id', function(id, vals, val, isAdd, isDisabled){
          var ids='';
          var video_id= $('.video_id').val();
          if(isAdd==true){
            $('.video_id').val(video_id);
          }else{
            //取消选中
            $('.video_id').val('');
          }

        });
      });

        var cate_id_str=$('.cate_id_str').val();
        if(cate_id_str){
          cate_id_str=cate_id_str.split(",");
        }
        layui.use(['layer','form','jquery','formSelects'],function(){
          $ = layui.jquery;
          var form = layui.form;
          layui.formSelects.data('cate_id_str', 'server', {
            url: '/admin/video/get_small_cate_list1?column_id='+column_id,
            linkage: false,
            linkageWidth: 130,
            header: {token: '4b36adc7ff355357'},
            success: function(id, url, searchVal, result){
              layui.formSelects.value('cate_id_str',cate_id_str );
            }
          });
          layui.formSelects.on('cate_id_str', function(id, vals, val, isAdd, isDisabled){
            var ids='';
            var troops_str1= $('.cate_id_str').val();
            if(isAdd==true){
              //选中
              ids+=val.val+',';
              $('.cate_id_str').val(troops_str1+ids);
            }else{
              //取消选中
              var new_troops_str=troops_str1.replace(val.val+',','');
              $('.cate_id_str').val(new_troops_str);
            }

          });
        });
      var video_url=$('.http').val()+$('.url').val();
      var videoObject = {
        container: '#video',//“#”代表容器的ID，“.”或“”代表容器的class
        variable: 'player',//该属性必需设置，值等于下面的new chplayer()的对象
        autoplay:true,//自动播放
        video:video_url//视频地址
      };
      var player=new ckplayer(videoObject);
    },300);

    form.on('select(column_id)', function(data){
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('video_time_id', 'server', {
          url: '/admin/video/get_video_time_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
      });
     /* layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('cate_id', 'server', {
          url: '/admin/video/get_small_cate_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
      });*/
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('cate_id_str', 'server', {
          url: '/admin/video/get_small_cate_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
        layui.formSelects.on('cate_id_str', function(id, vals, val, isAdd, isDisabled){
          var ids='';
          var cate_id_str1= $('.cate_id_str').val();
          if(isAdd==true){
            //选中
            ids+=val.val+',';
            $('.cate_id_str').val(cate_id_str1+ids);
          }else{
            //取消选中
            var new_cate_id_str=cate_id_str1.replace(val.val+',','');
            $('.cate_id_str').val(new_cate_id_str);
          }
        });
      });
      layui.use(['layer','form','jquery','formSelects'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layui.formSelects.data('address_id', 'server', {
          url: '/admin/video/get_address_list1?column_id='+data.value,
          linkage: false,
          header: {token: '4b36adc7ff355357'},
          linkageWidth: 130,

        });
      });
    });
  });
  layui.use(['form'], function(){
    var form = layui.form;
    setTimeout(function () {
      var menu_str=$('.tag_str').val();
      menu_str=menu_str.split(",");
      for(var i=0;i<menu_str.length;i++){
        $(".tag"+menu_str[i]).prop("checked", true);
      }
      form.render('checkbox');
    },300);

  });
  //日期时间选择器
  layui.use('laydate', function() {
    var laydate = layui.laydate;
    laydate.render({
      elem: '#test6'
      , type: 'datetime'
      ,min:0
    });
  });
  layui.data.done = function(d){
    layui.use(['form'], function(){
      var form = layui.form;
      form.render(); //渲染该模板下的动态表单
    });
  };
 /* layui.use('upload', function() {
    var $ = layui.jquery
            , upload = layui.upload;

    //普通图片上传
    var uploadInst = upload.render({
      elem: '#demo1'
      , url: '/admin/video/upload_videoimg'
      ,headers: {token: '4b36adc7ff355357'}
      ,accept:'images'
      ,size:2048
      , before: function (obj) {
        layer.load(1, {shade: [0.8, '#393D49']})//上传loading
        //预读本地文件示例，不支持ie8
        obj.preview(function (index, file, result) {
          $('#demo1').attr('src', result); //图片链接（base64）
        });

      }
      , done: function (res) {
        layer.closeAll('loading'); //关闭loading
        //如果上传失败
        if (res.code > 0) {
          return layer.msg('上传失败');
        }
        //上传成功
        $('.path').val(res.data.src);
      }
      , error: function () {
        layer.closeAll('loading'); //关闭loading
        //演示失败状态，并实现重传
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function () {
          uploadInst.upload();
        });
      }
    });

      //普通图片上传
      var uploadInst = upload.render({
        elem: '#demo2'
        , url: '/admin/video/upload_videoimg'
        ,headers: {token: '4b36adc7ff355357'}
        ,accept:'images'
        ,size:2048
        , before: function (obj) {
          layer.load(1, {shade: [0.8, '#393D49']})//上传loading
          //预读本地文件示例，不支持ie8
          obj.preview(function (index, file, result) {
            $('#demo2').attr('src', result); //图片链接（base64）
          });

        }
        , done: function (res) {
          layer.closeAll('loading'); //关闭loading
          //如果上传失败
          if (res.code > 0) {
            return layer.msg('上传失败');
          }
          //上传成功
          $('.rec_path').val(res.data.src);
        }
        , error: function () {
          layer.closeAll('loading'); //关闭loading
          //演示失败状态，并实现重传
          var demoText = $('#demoText2');
          demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
          demoText.find('.demo-reload').on('click', function () {
            uploadInst.upload();
          });
        }
      });
    upload.render({
      elem: '#test5'
      ,url: '/admin/video/upload_video'
      ,headers: {token: '4b36adc7ff355357'}
      ,accept: 'video' //视频
      ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        layer.load(1, {shade: [0.8, '#393D49']})//上传loading
      }
      ,error: function(index, upload){
        layer.closeAll('loading'); //关闭loading
        layer.msg('上传失败');
      }
      ,done: function(res){
        layer.closeAll('loading'); //关闭loading
        if (res.code > 0) {
          return layer.msg('上传失败');
        }
        layer.msg('上传成功');
        //上传成功
        $('.url').val(res.data.src);
        $('.video_time').val(res.data.video_time);
        var http_url=$('.http').val();
        $('.video_url').attr('src',http_url+res.data.src);
      }
    });

  });*/
</script>
